<?php
/**
 * Created by PhpStorm.
 * User: fengtian
 * Date: 15-3-19
 * Time: 上午11:21
 */
?>
<link rel="stylesheet" href="<?php echo URL::base() ?>media/vendor/css/style.css" type="text/css" media="all"/>
<link rel="stylesheet" href="<?php echo URL::base() ?>media/vendor/artdialog/skins/default.css" type="text/css"
      media="all"/>
<link href="<?php echo URL::base() ?>media/vendor/css/ui-lightness/jquery-ui-1.10.4.custom.css" rel="stylesheet">
<script src="<?php echo URL::base() ?>media/vendor/js/jquery-1.10.2.js"></script>
<script src="<?php echo URL::base() ?>media/vendor/js/jquery-ui-1.10.4.custom.js"></script>
<script src="<?php echo URL::base() ?>media/vendor/js/jquery.ui.datepicker-zh-TW.js"></script>
<script src="<?php echo URL::base() ?>media/vendor/js/Validform_v5.3.2_ncr_min.js"></script>
<script src="<?php echo URL::base() ?>media/vendor/artdialog/jquery.artDialog.js"></script>
<script src="<?php echo URL::base() ?>media/vendor/artdialog/plugins/iframeTools.js"></script>
<style>
    .table td, .table th {
        text-align: center;
    }

    .form-horizontal .control-label {
        width: 100px;
    }

    .form-horizontal .controls {
        margin-left: 110px;
    }

    a.xiazai:hover {
        text-decoration: none;
    }

    table tbody tr:nth-child(2n) {
        background-color: #f5f5f5;
    }

    .table th, .table td {
        border: 1px solid #ffffff;
    }
</style>

<script type="text/javascript">
    $(document).ready(function () {
        $('#table_content > tr:odd').css("background-color", "#f5f5f5");
    })
</script>
<div class="gy-navtent2">
    <form class="form-inline" id="search_form">
        <div class="control-group" style="padding-left: 70px">
            <label>库位：</label>

            <div class="input-append">
                <input class="span2" type="text" name="storage1"
                       value="<?php echo isset($get['storage1'])?$get['storage1']:''; ?>"
                       onkeyup="if(this.value.length>4 ){alert('数字超过了4位');this.value=this.value.substr(0,4);};this.value=this.value.replace(/\D/g,'')"
                       onafterpaste="if(this.value.length>4 ){alert('数字超过了4位');this.value=this.value.substr(0,4);};this.value=this.value.replace(/\D/g,'')"/>
                <span class="add-on">0000</span>
            </div>
            <label style="width: auto">到</label>

            <div class="input-append">
                <input class="span2" type="text" name="storage2"
                       value="<?php echo isset($get['storage2'])?$get['storage2']:''; ?>"
                       onkeyup="if(this.value.length>4 ){alert('数字超过了4位');this.value=this.value.substr(0,4);};this.value=this.value.replace(/\D/g,'')"
                       onafterpaste="if(this.value.length>4 ){alert('数字超过了4位');this.value=this.value.substr(0,4);};this.value=this.value.replace(/\D/g,'')"/>
                <span class="add-on">0000</span>
            </div>
        </div>
        <div class="control-group" style="padding-left: 70px">
            <label>搜索：</label>
            <input class="span2" type="text" placeholder="库位模糊搜索" name="storage"
                   value="<?php echo isset($get['storage'])?$get['storage']:''; ?>"/>
        </div>
        <div class="control-group" style="padding-left: 70px">
            <label>SKU：</label>
            <input class="span2" type="text" name='sku' value="<?php echo isset($get['sku'])?$get['sku']:''; ?>"/>
        </div>
        <div class="control-group" style="padding-left: 70px">
            <label>状态：</label>
            <select class="form-control span2" name='status' id="status">
                <option value="" selected="selected">全部</option>
                <?php if(isset($status) and $status){
                    foreach($status as $status_id => $_status){
                        ?>
                        <option
                            value="<?php echo $status_id ?>" <?php if(isset($get['status'])&&$get['status']==$status_id){
                            echo "selected='selected'";
                        } ?>>
                            <?php echo $_status ?>
                        </option>
                    <?php
                    }
                } ?>
            </select>
            <input type="submit" class="btn btn-info" value="查询"/>
            <input type="reset" value="重置" class="btn btn-inverse" id="reset_"/>
        </div>
        <div class="control-group">
            <label>订单号或追踪号：</label>
            <input class="span2 orders_ids" type="text" name='orders_id'/>
            <input type="button" class="btn btn-success" id="orders_id" value="确定"/>
        </div>
    </form>
</div>
<div>
    <label style="color: #ff0000">
        SKU更新日期为：<?php echo isset($record['add_time'])?$record['add_time']:0; ?>，
        需紧急盘点<?php echo isset($nums[3]['num'])?$nums[3]['num']:0 ?>个，
        已紧急盘点<?php echo isset($nums[4]['num'])?$nums[4]['num']:0 ?>个.
    </label>
    <table class="table table1 table-bordered" style="border-collapse: collapse;">
        <thead>
        <tr style="background-color:#4EA392;color:#fff; font-weight:bold;">
            <th>SKU</th>
            <th>中文名称</th>
            <th>储位</th>
            <th>期初库存</th>
            <th>本期入</th>
            <th>本期出</th>
            <th>总未发量</th>
            <th>库存量</th>
            <th>销售状态</th>
            <th>状态</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody id='table_content'>
        <?php
        if(isset($lists)){
            foreach($lists as $list):?>
                <tr>
                    <td><?php echo $list['sku'] ?></td>
                    <td><?php echo $list['sku_name'] ?></td>
                    <td><?php echo $list['storage'] ?></td>
                    <td><?php echo $list['qichu'] ?></td>
                    <td><?php echo $list['benqiru'] ?></td>
                    <td><?php echo $list['benqichu'] ?></td>
                    <td><?php echo $list['hold'] ?>  </td>
                    <td><?php echo $list['quantity'] ?>  </td>
                    <td><?php echo $list['onsale_name'] ?>  </td>
                    <td><?php echo $status[$list['status']]; ?></td>
                    <td>
                        <?php if($list['status']!=3){ ?>
                            <input type="button" class="btn btn-info" onclick="warning(this)" value="预警"/>
                        <?php }elseif($list['status']==3){ ?>
                            <input type="button" class="btn btn-success" value="已紧急预警"/>
                        <?php } ?>
                        <input type="hidden" value="<?php echo $list['sku']; ?>"/>
                        <input type="hidden" value="<?php echo $list['in_id']; ?>"/>
                        <input type="hidden" value="<?php echo $list['quantity'] ?>"/>
                    </td>
                </tr>
            <?php endforeach;
        } ?>
        <tr>
            <td colspan="13">
                <div><?php if(isset($page)){
                        echo $page;
                    } ?></div>
            </td>
        </tr>
        </tbody>
    </table>

</div>

<script>
    function warning(obj) {
        if (!window.confirm("确定预警吗?"))return false;
        var sku = $(obj).next().val();
        $.post('<?php echo url::base(TRUE);?>checkstock/warning', {'sku': sku}, function () {
            window.location.reload();
        });
    }

    $(function () {
        $.datepicker.setDefaults({ dateFormat: 'yy-mm-dd' });
        $("#start").datepicker({
        });

        $("input[name='storage1']").keyup(function () {
            $("input[name='storage2']").val($(this).val());
        })
        $("input[name='storage1']").blur(function () {
            if ($(this).val().length < 4) {
                var len = 4 - $(this).val().length;
                var str = new Array(len + 1).join("0");
                $(this).val($(this).val() + str);
                $("input[name='storage2']").val($(this).val());
            }

            //添加搜索功能
            if ($(this).val() == '0000') {
                if ($("input[name='storage2']").val() == '0000') {
                    $("input[name='storage']").css({"color": ""});
                    $("input[name='storage']").attr("disabled", false);
                } else {
                    $("input[name='storage']").css({"color": "#888"});
                    $("input[name='storage']").attr("disabled", true);
                }
            } else {
                $("input[name='storage']").css({"color": "#888"});
                $("input[name='storage']").attr("disabled", true);
            }
        });
        $("input[name='storage2']").blur(function () {
            if ($(this).val().length < 4) {
                var len = 4 - $(this).val().length;
                var str = new Array(len + 1).join("0");
                $(this).val($(this).val() + str);
            }

            //添加搜索功能
            if ($(this).val() == '0000') {
                if ($("input[name='storage_position1']").val() == '0000') {
                    $("input[name='storage']").css({"color": ""});
                    $("input[name='storage']").attr("disabled", false);
                } else {
                    $("input[name='storage']").css({"color": "#888"});
                    $("input[name='storage']").attr("disabled", true);
                }
            } else {
                $("input[name='storage']").css({"color": "#888"});
                $("input[name='storage']").attr("disabled", true);
            }
        });
        //上传表格
        $(".upSuppForm").Validform({
            tiptype: 2,
            postonce: true
        });

        //添加模糊搜索
        $("input[name='storage']").keyup(function () {
            if ($(this).val() == '') {
                $("input[name='storage1']").attr("disabled", false);
                $("input[name='storage2']").attr("disabled", false);
            } else {
                if ($(this).val() != '库位模糊搜索') {
                    $("input[name='storage1']").css({"color": "#888"});
                    $("input[name='storage2']").css({"color": "#888"});
                    $("input[name='storage1']").attr("disabled", true);
                    $("input[name='storage2']").attr("disabled", true);
                } else {
                    $("input[name='storage1']").attr("disabled", false);
                    $("input[name='storage2']").attr("disabled", false);
                }
            }
        });
        $("#reset_").click(function () {
            $("input[name='storage1']").attr("disabled", false);
            $("input[name='storage2']").attr("disabled", false);
            $("input[name='storage']").attr("disabled", false);
        });

        //扫描功能
        //1.按“确定”键查询
        $("#orders_id").click(function () {
            var id = $(this).siblings("input").eq(0).val();
            $("#table_content").empty();
            $.get("<?php echo URL::base()?>checkstock/show",
                {erp_id: id},
                function (data) {
                    var obj = jQuery.parseJSON(data);
                    if (obj.status == 'Y') {
                        $("#table_content").html(obj.view);
                    } else {
                        art.dialog({
                            time:2,
                            content:obj.info
                        });
                    }
                    $(".orders_ids").val("");
                    $(".orders_ids").focus();
                }
            )
        });
        //2.按“Enter”键查询
        $(".orders_ids").keydown(function (e) {
            $("#table_content").empty();
            if(e.keyCode==13){
                e.preventDefault();
                var id = $(this).val();
                $.get("<?php echo URL::base()?>checkstock/show",
                    {erp_id: id},
                    function (data) {
                        var obj = jQuery.parseJSON(data);
                        if (obj.status == 'Y') {
                            $("#table_content").html(obj.view);

                        } else {
                            art.dialog({
                                time:2,
                                content:obj.info
                            });
                        }
                        $(".orders_ids").val("");
                        $(".orders_ids").focus();
                    }
                )
            }
        });
    })

</script>
